<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<base href="<%=basePath %>" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>农资与农产品全程供应链物流平台-新增司机信息</title>
<meta name="kewywords" content="农资与农产品全程供应链物流平台"/>
<meta name="description" content="农资与农产品全程供应链物流平台"/>
<link href="css/style.css" type="text/css" rel="stylesheet"/>
<link type="text/css" rel="stylesheet" href="css/jquery-ui.css" />	
<script language="javascript" type="text/javascript" src="js/js.js"></script>
<script type="text/javascript" src="js/jquery-1.9.1.js"></script>
<script type="text/javascript" src="js/jquery-ui.js"></script>
	<script type="text/javascript">
		$(document).ready(function(){
			if($("#selectIds").val() != "" ){
			//alert($("#selectIds").val());
				var selectIds = $("#selectIds").val().split(",");					
				if(selectIds[0] == 0){
					$("#male").click();
				}else if(selectIds[0] == 1){
					$("#female").click();
				}	
				// 选中驾照类型
				//alert(selectIds[1]);
				setSelectedValue("licenseType",selectIds[1]);					
				//alert(selectIds[2]);
				// 选中司机状态
				setSelectedValue("state",selectIds[2]);
			}

			var birthday = $("#birthday").val();
			var validFrom = $("#validFrom").val();	
			$("#validFromDate").val(validFrom);
			$("#birthDate").val(birthday);
		});
		function setSelectedValue(id,value){
			//alert(id + value);
			var obj = document.getElementById(id);
			//alert(obj);
			for( i = 0;obj.options.length > i; i++){
				if(obj.options[i].value == value){
					obj.options[i].selected = true;
					return;
				}
			}
		}
		$(function(){
			$("#validFromDate").datepicker({					
				changeMonth: true,
      			changeYear: true,
      			dateFormat: "yy-mm-dd",
      			showButtonPanel: true,
      			yearRange: "2008:2013",
      			closeText: "Close",
      			currentText: "Now" //,
      			//monthNames:["1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月"]     			
			});
			$("#birthDate").datepicker({					
				changeMonth: true,
      			changeYear: true,
      			dateFormat: "yy-mm-dd",
      			yearRange: "1970:2012",
      			closeText: "Close",
      			currentText: "Now" //,
      			//monthNames:["1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月"]
			});	
		});	
		function saveCheck(){
			//alert($("#birthDate").val());
			if($("#driver").val() == ""){
				alert("姓名不能为空");
				return false;
			}
			if($("#idCardNo").val() == ""){
				alert("身份证号码不能为空");
				return false;
			}else if($("#idCardNo").val() != ""){
				var sID = $("#idCardNo").val();
				if(!(/^\d{18}$|^\d{17}[xX]$/.test(sID))){
					alert("请输入有效的18位身份证号码");
					return false;
				}
			}
			if($("#telephone").val() == ""){
				alert("请填写手机号码");
				return false;
			}else if($("#telephone").val() != ""){
				var phone = $("#telephone").val();
				//alert(phone);
				if($.trim(phone).length > 11 || 11 > $.trim(phone).length){
					alert("请输入11位手机号码");
					return false;
				}					
			}
			if($("#birthDate").val() == ""){
				alert("出生日期不能为空");
				return false;
			}
			if($("#address").val() == ""){
				alert("地址不能为空");
				return false;
			}
			if($("#validFromDate").val() == ""){
				alert("驾照有效起始日期不能为空");
				return false;
			}
			if($("#validPeriod").val() == ""){
				alert("驾照有效期限不能为空");
				return false;
			}
			//alert("OK");
			$("#birthday1").val($("#birthDate").val());
			$("#validFrom1").val($("#validFromDate").val());
			$("#driverInfo").submit();
		}
		function Check_Mobiles(phone){
        	return (/^((13|15|18|14)+\d{9})$/).test(phone);
        }	
		
		function  check(val){
			if(val==1){
				if($("#driver").val() == ""||$.trim($("#driver").val()) == ""){
					$("#driverTip").html("<font color=\"red\">姓名不能为空</font>");
					return false;
				}else{
					$("#driverTip").html("<font color=\"red\"></font>");	
				}
				
			}
			if(val==2){
				if($("#address").val() == ""||$.trim($("#address").val()) == ""){
					$("#addressTip").html("<font color=\"red\">地址不能为空</font>");
					return false;
				}else{
					$("#addressTip").html("<font color=\"red\"></font>");	
				}
				
			}
			if(val==3){
				var socialNo = $("#idCardNo").val();
				if(socialNo == ""){
					$("#idCardNoTip").html("<font color=\"red\">身份证号码不能为空</font>");
				}
				else if (socialNo != "") {
					if (socialNo.length != 15 && socialNo.length != 18) {
						$("#idCardNoTip").html("<font color=\"red\">身份证号码输入长度不正确</font>");
						return (false);
					}
					var area = { 11 : "北京", 12 : "天津", 13 : "河北", 14 : "山西", 15 : "内蒙古", 21 : "辽宁", 22 : "吉林", 23 : "黑龙江", 31 : "上海", 32 : "江苏", 33 : "浙江", 34 : "安徽", 35 : "福建", 36 : "江西", 37 : "山东",
						41 : "河南", 42 : "湖北", 43 : "湖南", 44 : "广东", 45 : "广西", 46 : "海南", 50 : "重庆", 51 : "四川", 52 : "贵州", 53 : "云南", 54 : "西藏", 61 : "陕西", 62 : "甘肃", 63 : "青海", 64 : "宁夏", 65 : "新疆",
						71 : "台湾", 81 : "香港", 82 : "澳门", 91 : "国外" };

					if (area[parseInt(socialNo.substr(0, 2))] == null) {
						$("#idCardNoTip").html("<font color=\"red\">身份证号码不正确(地区非法)!</font>");
						return (false);
					}
					if (socialNo.length == 15) {
						pattern = /^\d{15}$/;
						if (pattern.exec(socialNo) == null) {
							$("#idCardNoTip").html("<font color=\"red\">15位身份证号码必须全为数字！ </font>");
							return (false);
						}
						var birth = parseInt("19" + socialNo.substr(6, 2));
						var month = socialNo.substr(8, 2);
						var day = parseInt(socialNo.substr(10, 2));
						switch (month) {
						case '01':
						case '03':
						case '05':
						case '07':
						case '08':
						case '10':
						case '12':
							if (day > 31) {
								$("#idCardNoTip").html("<font color=\"red\">输入身份证号码日期格式不正确! </font>");
								return false;
							}
							break;
						case '04':
						case '06':
						case '09':
						case '11':
							if (day > 30) {
								$("#idCardNoTip").html("<font color=\"red\">输入身份证号码日期格式不正确! </font>");
								return false;
							}
							break;
						case '02':
							if ((birth % 4 == 0 && birth % 100 != 0) || birth % 400 == 0) {
								if (day > 29) {
									$("#idCardNoTip").html("<font color=\"red\">输入身份证号码日期格式不正确! </font>");
									return false;
								}
							} else {
								if (day > 28) {
									$("#idCardNoTip").html("<font color=\"red\">输入身份证号码日期格式不正确! </font>");
									return false;
								}
							}
							break;
						default:
							$("#idCardNoTip").html("<font color=\"red\">输入身份证号码日期格式不正确! </font>");
							return false;
						}
						if (result<15 || result>100) {
							$("#idCardNoTip").html("<font color=\"red\">输入身份证号码日期格式不正确! </font>");
							return false;
						}
					} else if (socialNo.length == 18) {
						var Wi = new Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2, 1);
						var lSum = 0;
						var nNum = 0;

						for (var i = 0; i < 17; ++i) {

							if (socialNo.charAt(i) < '0' || socialNo.charAt(i) > '9') {
								$("#idCardNoTip").html("<font color=\"red\">输入身份证号码格式不正确! </font>");
								return (false);
							} else {
								nNum = socialNo.charAt(i) - '0';
							}
							lSum += nNum * Wi[i];
						}

						if (socialNo.charAt(17) == 'X' || socialNo.charAt(17) == 'x') {
							lSum += 10 * Wi[17];
						} else if (socialNo.charAt(17) < '0' || socialNo.charAt(17) > '9') {
							$("#idCardNoTip").html("<font color=\"red\">输入身份证号码格式不正确! </font>");
							return (false);
						} else {
							$("#idCardNoTip").html("<font color=\"red\"></font>");
						}
					}
				} 
					
				
			}
			if(val==4){
				if ("" == $("#telephone").val() || $.trim($("#telephone").val()) == "") {
					$("#telephoneTip").html("<font color=\"red\">联系电话不能为空</font>");
					return false;
				} else {
					var s= $("#telephone").val();
					var w = 0;   
					for (var i=0; i<s.length; i++) {   
					   var c = s.charCodeAt(i);   
					   //单字节加1   
					   if ((c >= 0x0001 && c <= 0x007e) || (0xff60<=c && c<=0xff9f)) {   
					    w++;   
					   }   
					   else {   
					    w+=2;   
					    
					   }   
					}   
					if (w==11) {   
						$("#telephoneTip").html("<font color=\"red\"></font>");
					}else{
						$("#telephoneTip").html("<font color=\"red\">联系电话必须是11位的数字</font>");
					}   
				}
			}
			if(val==5){
				if($("#birthDate").val() == ""||$.trim($("#birthDate").val()) == ""){
					$("#birthDateTip").html("<font color=\"red\">出生日期不能为空</font>");
					return false;
				}else{
					$("#birthDateTip").html("<font color=\"red\"></font>");	
				}
				
			}
			if(val==6){
				if($("#validFromDate").val() == ""||$.trim($("#validFromDate").val()) == ""){
					$("#validFromDateTip").html("<font color=\"red\">驾照有效起始日期不能为空</font>");
					return false;
				}else{
					$("#validFromDateTip").html("<font color=\"red\"></font>");	
				}
				
			}
			if(val==7){
				if($("#validPeriod").val() == ""||$.trim($("#validPeriod").val()) == ""){
					$("#validPeriodTip").html("<font color=\"red\">驾照有效期限不能为空</font>");
					return false;
				}else{
					$("#validPeriodTip").html("<font color=\"red\"></font>");	
				}
				
			}
		}
		
		</script>
</head>
<body>
<%@include file="top.jsp" %>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td width="187" height="37" bgcolor="#e0e0e0" class="brt bbt"><div class="topleft fl">系统菜单栏</div></td>
    <td bgcolor="#e7e7e7" class=" bbt"><div class="topleft fl">您现在的位置：<a href="#">首页</a>&nbsp;&gt;&nbsp;<span>新增司机</span></div></td>
  </tr>
  <tr>
    <td width="187" height="100%" valign="top" bgcolor="#FFFFFF" class="brt">
    	<div class="left_bk"> 
           <div class="menu2">
          <%@include file="database_left.jsp" %>
          </div>    
        </div>
     </td>
        
    <td align="left" valign="top" bgcolor="#FFFFFF">
    <div class="content">
      <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
        <tr>
          <td height="38" style="background:url(images/zz_tit.jpg) left top repeat-x;">
          	<div class="tt_back fl">新增司机</div>
          	<div class="fr"><img src="images/tit_right.jpg" alt="" width="103" height="38" /></div>
          </td>
        </tr>
        <tr>
          <td class="borders btn">
          <table width="100%" border="0" cellspacing="0" cellpadding="0">
		  <tr>
		    <td bgcolor="#fffeee" style="border-bottom:#fee7bd solid 1px;" >
		    	<form action="saveDriver" method="post" id="driverInfo">
				  	<s:hidden name="selectIds" id="selectIds" />
				  	<s:hidden name="birthday" id="birthday"/>
				  	<s:hidden name="validFrom" id="validFrom"/>
				  	<input type="hidden" name="birthday1" id="birthday1" value=""/>
				  	<input type="hidden" name="validFrom1" id="validFrom1" value=""/>
					<div style="height:500px">
				    <table border="0" cellspacing="0" cellpadding="0" align="left" style="margin-top:20px;margin-left: 100px;margin-bottom: 20px; " >
			            <tr style="height: 40px;">
			  			<td align="right" width="100px;"><span style="color: red">*</span>姓名：</td>
			  			<td  width="180px;">
			  				<input type="text" id="driver" name="driver.driver" value="${driver.driver}"
			  					class="input_are w122"  onblur="check(1)"/><br><span id="driverTip"></span></td>
			  			<td align="right"><span style="color: red">*</span>身份证号码：</td>
			  			<td width="180px;">
			  				<input type="text" id="idCardNo" name="driver.idCardNo" value="${driver.idCardNo}" 
			  					style="width: 200px;" class="input_are w122" onblur="check(3)"/><span id="idCardNoTip"></span></td>	  			
			  			</tr>
			  			<tr style="height: 40px;">
			  			<td align="right"><span style="color: red">*</span>性&nbsp;&nbsp;&nbsp;&nbsp;别：</td>
			  			<td width="180px;">
			  				<input type="radio" name="driver.sex" id="male" value="0" checked="checked"/>
			 					<label for="male">男</label>&nbsp;&nbsp;&nbsp;&nbsp;
							<input type="radio" name="driver.sex" id="female" value="1"/>
								<label for="female">女</label>
			  			</td>
			  			<td align="right"><span style="color: red">*</span>手机号码：</td>
			  			<td width="180px;">
							<input id="telephone" name="driver.telephone" value="${driver.telephone}"
								style="width: 200px;" class="input_are w122" onblur="check(4)"/><span id="telephoneTip"></span>
			  			</td>
			  			</tr>
			  			<tr style="height: 40px;">
			  			<td align="right"><span style="color: red">*</span>出生日期：</td>
			  			<td width="180px;">
			  				<input type="text" id="birthDate" class="input_are w122" onblur="check(5)"/><br/><span id="birthDateTip"></span></td>
			  			<td align="right"><span style="color: red">*</span>地址：</td>
			  			<td width="180px;">
			  				<input id="address" name="driver.address" value="${driver.address}"
			  					style="width: 200px;" class="input_are w122" onblur="check(2)"/><span id="addressTip"></span>
			  			</td>
			  			</tr>
			  			<tr style="height: 40px;">
			  			<td align="right"><span style="color: red">*</span>驾照类型：</td>
			  			<td width="180px;">
			  			<select id = "licenseType" name="driver.licenseType" class="input_are w122">
								<option value="A1" selected="selected">A1</option>
								<option value="A2">A2</option>
								<option value="C1">C1</option>
								<option value="C2">C2</option>
							</select>
			  			</td>
			  			<td align="right">司机状态：</td>
			  			<td width="180px;">
			  				<select id="state" name="driver.state" class="input_are w122">
								<option value="空闲" selected="selected">空闲</option>
								<option value="出车">出车</option>
							</select>
			  			</td>
			  		</tr>
			  		<tr style="height: 40px;">
			  			<td align="right"><span style="color: red">*</span>驾照起始日期: </td>
			  			<td width="180px;">
			  				<input type="text" id="validFromDate" class="input_are w122" onblur="check(6)"/><br/><span id="validFromDateTip"></span></td>
			  			<td align="right" width="180px;"><span style="color: red">*</span>驾照有效期：</td>
			  			<td>
			  				<input type="text" id="validPeriod" name="driver.validPeriod" value="${driver.validPeriod}" 
			  					style="width: 200px;" class="input_are w122"  onblur="check(7)"/><span id="validPeriodTip"></span></td>
			  		</tr>
			  		<tr style="height: 40px;">
			  			<td colspan="2" align="center">
			  				<input type="button" style="cursor: pointer;" class="buttons" value="保  存" onclick="saveCheck()" /></td>
			  			<td colspan="2" align="center">
			  				<input type="reset" style="cursor: pointer;" class="buttons" value="重  置" /></td>
			  		</tr>
				</table>
				</div>
			</form>
		</td>
		  </tr>
		    </table></td>
		  </tr>
		</table>
		</div>
		</td>
        </tr>
      </table>
<div class="bottom">版权所有：安徽朗坤物联网</div>
</body>
</html>